import React from 'react';
import {connect} from 'react-redux';
import HeadNavComponent from "../../../components/headNav";
import {safeAuto,GoPagePush} from "../../../assets/js/utils";
import request from '../../../assets/js/utils/request';
import  Css from '../../../assets/css/user/address/index.css';
class addressComponent extends React.Component{
    constructor(props){
        super(props);
        safeAuto(props);
        this.state={
            aAddress:[]
        }
    }
    componentDidMount(){
        this.getDataAddress()
    }
    componentWillUnmount(){
        this.setState = (state, callback) => {
            return;
        };
    }
    getDataAddress(){
        let sUrl=window.base.config.baseUrl+'user/address/index?uid='+this.props.state.redLogin.uid+'&token='+window.base.config.token;
        request(sUrl,'get').then(res=>{
            console.log(res)
            if (res.code===200){
                this.setState({aAddress:res.data})
            }
        })
    }
    goPage(url){
        GoPagePush(this.props,url)
    }
    render(){
        return(
            <div className={Css['main']}>
                <HeadNavComponent title={'选择收货地址'} ></HeadNavComponent>
                <div className={Css['address_list']}>
                    <ul>
                        {
                            this.state.aAddress.length>0?
                                this.state.aAddress.map((item,index)=>{
                                    return(
                                        <li key={index} onClick={this.goPage.bind(this,'user/address/mod?aid='+item.aid)}>
                                            <div className={Css['address_list_font']}>
                                                <div className={Css['address_list_font_r']}>
                                                    <div className={Css['address_list_font_cont']}>
                                                        <span>{item.name}</span><span>{item.cellphone}</span>
                                                    </div>
                                                    <div className={Css['address_list_font_area']}>
                                                        {item.isdefault==='1'?<i>默认</i>:''}
                                                        <span className={'ovflOne'}>{item.province}{item.city}{item.area}{item.aAddress}</span>
                                                    </div>
                                                </div>
                                            </div>
                                        </li>
                                    )
                                })
                                :''
                        }
                    </ul>
                </div>
                <div className={Css['subim']} onClick={this.goPage.bind(this,'address/add')}>+添加收获地址</div>
            </div>
        )
    }
}
export default connect((state)=>{
    return{
        state:state
    }
})(addressComponent)